#ifndef PACKET_PROCESSER_HPP_
#define PACKET_PROCESSER_HPP_

#include <map>

#include "../lge2d.hpp"
#include "packet.hpp"

namespace lge2d
{
namespace lan
{
// базовая команда. Не используется в клиенте
class CommandHandlerBase
{
public:
	virtual ~CommandHandlerBase() {}

	virtual void operator()(Packet& packet) = 0;
};

// шаблон хэндлера команды
template<class TObject, class TCommand>
struct CommandHandler : public CommandHandlerBase
{

public:
	typedef void (TObject::*method_t)(const TCommand&);

	CommandHandler(TObject* obj, method_t method) :
		m_object(obj), m_method(method)
	{
	}

	virtual void operator()(Packet& packet)
	{
		TCommand cmd;
		packet >> cmd;
		(m_object->*m_method)(cmd);
	}

private:
	TObject* m_object;
	method_t m_method;
};

} /* namespace lan */
} /* namespace lge2d */

#endif /* PACKET_PROCESSER_HPP_ */
